package com.olympia.myapp.util;

import java.util.Vector;

public class StringUtil {

	/*
	 * Ham cat chuoi thanh mang nhieu phan tu theo mot ky tu duoc chi dinh
	 * 
	 * @param String oringnal : chuoi du lieu dua vao
	 * 
	 * @Param String speparator chuoi ky tu de nhan biet
	 * 
	 * @return Vector
	 */
	public static Vector<String> split(String original, String separator) {
		Vector<String> nodes = new Vector<String>();
		// Parse nodes into vector
		int index = original.indexOf(separator);
		while (index >= 0) {
			if (index > 0) {
				nodes.addElement(original.substring(0, index));
				original = original.substring(index + separator.length());
			} else {
				nodes.add("");
				++index;
				if (index < original.length())
					original = original.substring(index, original.length());
				else
					original = original.substring(index);

			}
			
			if (original.contains(separator))
				index = original.indexOf(separator);
			else
				break;
		}
		// Get the last node
		if (original.length() > 0)
			nodes.addElement(original);
		else
			nodes.addElement("");
		return nodes;
	}

}
